/**
 * 入口文件
 */
import Vue from 'vue';
import App from './App.vue';

import VueRouter from 'vue-router';
import VueResource from 'vue-resource';
import registerRouters from './routers';

//import vueLazyLoad from './directives/lazyload';
import vueSwiper from './directives/vue-swiper';

import jskit from './assets/jskit';
import auth from './utils/auth';

//注册插件
[
    VueRouter,
    VueResource
].map((item)=>{
    Vue.use(item)
});

var router = new VueRouter({
  hashbang: false,
  history: true,
  //saveScrollPosition: true
});

//Vue.http.options.emulateJSON = true;
Vue.http.options.beforeSend = function(request){
  request.url = jskit.utils.addParam(request.url,{
    token:auth.getToken()
  })
}

//增加权限控制
router.beforeEach(function ({ to, next }) {
    if(to.auth){
        if(jskit.isWechat){
          if(!auth.getToken()){
            return jskit.toLogin();
          }
          jskit.hideMenuItems(3);
        }
    }
    next();
});

//注册指令
//vueLazyLoad(Vue);
vueSwiper(Vue);

registerRouters(router);

router.start(App, 'app');
